//
// MIDIAnalyser is a soft for MID extension song statistical analysis
// Calculating fractal dimmension and detecting fractal sign of a musical piece 
// Generating melody based on a loaded composition
// Created as part of Vilnius University bachelor work: Fractals application in musical sound analysis.
// Author: Aleksandr Voronovic
//

MidSong midSong;
StatCalculator statCalculator;
FractalFinder finder;
Plotter plotDrawer;
SCScore score;
GUI ui;
boolean debug;
int generateLen;
int leaveLen;
String currentTrackName;

TrackStats testTrack;
boolean doSaveFile;

void setup() {
  size(800, 640, P2D);
  debug = false;
  doSaveFile = true;
  generateLen = 10;
  currentTrackName = "";
  midSong = new MidSong();
  plotDrawer = new Plotter();
  ui = new GUI();
}


void calculateStats(int i){
  statCalculator = new StatCalculator(midSong);
  statCalculator.claculateSongStatistics();

  score = new SCScore();
  score.tempo(midSong.tempo);
  score.instrument(statCalculator.tracks.get(i).instrument);

  finder = new FractalFinder(statCalculator.tracks.get(i));
  setupSliders();
  plotDrawer.notesList = finder.calcNotesPoints();
  plotDrawer.durationsList = finder.calcDurationsPoints();
  plotDrawer.velocityesList = finder.calcVelocityesPoints();
}


void draw() {
  background(20);
  text(currentTrackName, width/2-currentTrackName.length()*4, 30);
  plotDrawer.plot();
}

